<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
		$model = M('type');
		$plists = $model->select();
		//echo '<pre>';
		//print_r($plists);
		$this->assign('rows', $plists);
		$this->display();
    }
	
	public function index2(){
		$info = I('get.');
		//echo $pid['pid'];
		//echo '<pre>';
		//print_r($info);
		$model = M('type');
		if($info['id'] == -1){
			//$roots = $model->where($pid)->select();
			//print_r($plists);
			//$this->assign('roots', $roots);
			$path = array('pid' => $info['pid']);
			$rows = $model->where($path)->select();
			$this->assign('rows',$rows);
			$this->display('Index2/index2');
		}else{
			$path =array('path' => $info['path'] . $info['id'] . ',');
			//echo $path;
			$rows = $model->where($path)->select();
			$rowpath = $model->where($path)->getField('path');
			//echo $row;
			$rootpath = explode(',', $rowpath);
			$rootArr = array();
			$i = 0;
			foreach( $rootpath as $row){
				$rootArr[] = intval(trim($row));
				$i++;
			}
			//print_r($rootArr);
			//echo $i;
			$rootName = array();
			for($j = 1;$j <$i-1;$j++){
				$id = array('id' => $rootArr[$j]);
				$rootName[$j-1]['name'] = $model->where($id)->getField('name');
				$rootName[$j-1]['path'] = $model->where($id)->getField('path');
				$rootName[$j-1]['id'] = $model->where($id)->getField('id');
			}
			//print_r($rootName);
			
			$this->assign('roots', $rootName);
			$this->assign('rows', $rows);
			$this->display('Index2/index2');
		}
	}
}












